<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 原型链继承
    function Person(name) {
        this.name = name;
        this.children = [];
        this.sum = function () {
            alert(this.name);
        }

    }
    Person.prototype.age = 18;

    function Per(a) {
        // this.name = a;
    }
    console.log(Person.prototype);
    Per.prototype = new Person(); // 原型链继承关键
    Per.prototype.luo = '13124';
    var per1 = new Per();
    var per2 = new Per();
    per1.children.push(1);
    per1.name = 'luo';
    console.log(per1.name, per2.name);
    console.log(per1.__proto__);

    // 借用构造函数继承
    function Con() {
        Person.call(this, 'luosir'); //借用构造函数继承关键
        this.age = 20;
    }
    var con1 = new Con();
    console.log(con1.age);

    // 组合继承
    function subType(name) {
        Person.call(this, name);
    }
    subType.prototype = new Person();
    var sub = new subType('luojianming');
    console.log(sub.name);
    console.log(sub.age);

    // 寄生组合式继承1
    function A(params) {
        Person.call(this, params)
    }
    function JiSheng(son, parent) {
        var clone = Object.create(parent.prototype);//创建对象
        son.prototype = clone;      //指定对象
        clone.constructor = son;     //增强对象
    }
    JiSheng(A, Person)
    var a = new A();
    console.log(a.name);
    console.log(a.age);

    // 寄生组合式继承2
    function Parent(name) {
        this.name = name
    }
    Parent.prototype.age = 18;
    function Son(a) {
        Parent.call(this, a)
    }
    Son.prototype = Object.create(Parent.prototype)
    Son.prototype.constructor = Son
    var a = new Son('luo')
    console.log(a.name);
    console.log(a.age);
    console.log(a.__proto__.constructor);
</script>

</html>